<?php
namespace Home\Controller;
use Think\Controller;
header('content-type:text/html;charset=utf-8');
class GetPK10DataController extends Controller {
	public function index(){
		$data = DeleteHtml(curlGet("http://www.qm368.com/lotteryV3/draw/hisresult.do?lotCode=BJSC"));
        preg_match('/<tr class=\"bgcolor1\"><td class=\"td1\">(.*?)<\/td><td class=\"td1\">(.*?)<\/td><td class=\"td2\">(.*?)<\/td>/',$data,$m_issue);
        $periodnumber = $m_issue[3];//获取期号
        $awardtime    = $m_issue[1]." ".$m_issue[2];//开奖时间
         preg_match('/<td class=\"td3\"><span class=\"result\"> <span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><span class=\"pk10 b(.*?)\"><\/span><\/span><\/td>/',$data,$m_number);
        $awardnumbers=$m_number[1].",".$m_number[2].",".$m_number[3].",".$m_number[4].",".$m_number[5].",".$m_number[6].",".$m_number[7].",".$m_number[8].",".$m_number[9].",".$m_number[10];//获取开奖号码

		if(F('pk10_No')!=$periodnumber){
					if(F('pk10_number')!=$awardnumbers)
					{
						$res = M('number')->where("periodnumber = {$periodnumber}")->find();
					    if(!$res){
						$map['awardnumbers'] = $awardnumbers;//开奖号码
						$map['awardtime'] = $awardtime;//开奖公告时间
						$map['time'] = strtotime($awardtime);//要存储时间
						$map['periodnumber'] = $periodnumber;//期号
						$info = explode(',', $map['awardnumbers']);
						for($i=0;$i<count($info);$i++){
							if($info[$i]<10){
								$info[$i] = substr($info[$i], 1);
							}
						}
						$map['number'] = serialize($info);
						if($info[0]>$info[9]){
							$lh[0] = '龙';
						}else{
							$lh[0] = '虎';
						}
						if($info[1]>$info[8]){
							$lh[1] = '龙';
						}else{
							$lh[1] = '虎';
						}
						if($info[2]>$info[7]){
							$lh[2] = '龙';
						}else{
							$lh[2] = '虎';
						}
						if($info[3]>$info[6]){
							$lh[3] = '龙';
						}else{
							$lh[3] = '虎';
						}
						if($info[4]>$info[5]){
							$lh[4] = '龙';
						}else{
							$lh[4] = '虎';
						}
						$map['lh'] = serialize($lh);
						$map['tema'] = $info[0]+$info[1];
						if($map['tema'] % 2 == 0){
							$map['tema_ds'] = '双';
						}else{
							$map['tema_ds'] = '单';
						}
						if($map['tema']>=12){
							$map['tema_dx'] = '大';
						}else{
							$map['tema_dx'] = '小';
						}
						if($map['tema']>=3 && $map['tema']<=7){
							$map['tema_dw'] = 'A';
						}
						if($map['tema']>=8 && $map['tema']<=14){
							$map['tema_dw'] = 'B';
						}
						if($map['tema']>=15 && $map['tema']<=19){
							$map['tema_dw'] = 'C';
						}
						if($info[0]>$info[1]){
							$map['zx'] = '庄';
						}else{
							$map['zx'] = '闲';
						}
						$res1 = M('number')->add($map);
						if($res1){
							F('pk10_No',$periodnumber);
	        				F('pk10_time',$awardtime);
	        				F('pk10_number',$awardnumbers);
							echo "保存成功：".+$periodnumber;
						}
					}
				}
				else{
					echo "已存在记录".+$awardnumbers;
				}
			}else{
				echo "已存在记录".+$periodnumber;
			}
	}
	

}?>